//
//  BGFindpayController.m
//  bigMall
//
//  Created by ios on 16/7/25.
//  Copyright © 2016年 thinklev. All rights reserved.
//

#import "BGFindpayController.h"
#import "BGDateResult.h"

@interface BGFindpayController () {
    
    UITextField *numFiled;
    UITextField *yzmFiled;
    UITextField *xpwdFiled;
    UITextField *querenpwd;
    UIButton *_btn;
    UIButton *yanzhengBtn;
    
}

@end

@implementation BGFindpayController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.title = @"找回支付密码";
    
    [self createUI];
    
}

- (void)createUI {
    
    for (int i = 1; i <= 5; i++) {
        
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(21, (i - 1) * 64 + 64, self.view.bounds.size.width - 42, 1)];
        
        if (i == 1) {
            
            view.hidden = YES;
            
        }
        
        view.backgroundColor = [UIColor lightGrayColor];
        
        view.alpha = 0.3;
        
        [self.view addSubview:view];
        
    }
    
    //手机号
    UILabel *numLab = [[UILabel alloc] initWithFrame:CGRectMake(21, 64 / 3 + 64 - 64 + 64, BGWidth / 3, 64 / 3)];
    
    numLab.text = @"手机号：";
    numLab.font = [UIFont systemFontOfSize:15];
    CGSize sizenum = [numLab.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:numLab.font,NSFontAttributeName, nil]];
    numLab.frame = CGRectMake(21, 64 / 3 + 64 - 64 + 64, sizenum.width, sizenum.height);
    numLab.textAlignment = NSTextAlignmentLeft;
    [self.view addSubview:numLab];
    
    numFiled = [[UITextField alloc] initWithFrame:CGRectMake(numLab.right, numLab.y, 160, numLab.height)];
    
    numFiled.clearButtonMode = UITextFieldViewModeAlways;
    numFiled.placeholder = @"请输入手机号";
    
    [self.view addSubview:numFiled];
    
    //验证码
    UILabel *pwdLab = [[UILabel alloc] initWithFrame:CGRectMake(21, 256 / 3 + 65 - 64 + 64, BGWidth / 3, 64 / 3)];
    
    pwdLab.text = @"验证码：";
    pwdLab.font = [UIFont systemFontOfSize:15];
    pwdLab.textAlignment = NSTextAlignmentLeft;
    CGSize sizepwd = [pwdLab.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:pwdLab.font,NSFontAttributeName, nil]];
    pwdLab.frame = CGRectMake(21, 256 / 3 + 65 - 64 + 64, sizepwd.width, sizepwd.height);
    [self.view addSubview:pwdLab];
    
    yzmFiled = [[UITextField alloc] initWithFrame:CGRectMake(pwdLab.right, pwdLab.y, BGWidth / 2.5, pwdLab.height)];
    
    yzmFiled.placeholder = @"请输入验证码";
    
    yzmFiled.secureTextEntry = YES;
    
    [self.view addSubview:yzmFiled];
    
    yanzhengBtn = [[UIButton alloc] initWithFrame:CGRectMake(yzmFiled.right, pwdLab.y - 15, BGWidth - 21 - yzmFiled.right, pwdLab.height + 30)];
    
    [yanzhengBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    [yanzhengBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
    
    yanzhengBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    
    [yanzhengBtn setBackgroundColor:[UIColor redColor]];
    
    yanzhengBtn.clipsToBounds = YES;
    yanzhengBtn.layer.cornerRadius = 10;
    
    [yanzhengBtn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:yanzhengBtn];
    
    //新支付密码
    UILabel *authLab = [[UILabel alloc] initWithFrame:CGRectMake(21, 64 * 7 / 3 + 66 - 64 + 64, BGWidth / 3, 64 / 3)];
    
    authLab.text = @"新支付密码：";
    authLab.font = [UIFont systemFontOfSize:15];
    authLab.textAlignment = NSTextAlignmentLeft;
    CGSize sizeauth = [authLab.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:authLab.font,NSFontAttributeName, nil]];
    authLab.frame = CGRectMake(21, 64 * 7 / 3 + 66 - 64 + 64, sizeauth.width, sizeauth.height);
    [self.view addSubview:authLab];
    
    xpwdFiled = [[UITextField alloc] initWithFrame:CGRectMake(authLab.right, authLab.y, BGWidth - 21 - authLab.right, authLab.height)];
    
    xpwdFiled.placeholder = @"请输入由六位数字组成的新密码";
    
    xpwdFiled.secureTextEntry = YES;
    
    [self.view addSubview:xpwdFiled];
    
    //确认新密码
    UILabel *xla = [[UILabel alloc] initWithFrame:CGRectMake(21, 64 * 10 / 3 + 67 - 64 + 64, BGWidth / 3, 64 / 3)];
    xla.text = @"确认新密码：";
    xla.font = [UIFont systemFontOfSize:15];
    xla.textAlignment = NSTextAlignmentLeft;
    CGSize sizexla = [xla.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:xla.font,NSFontAttributeName, nil]];
    xla.frame = CGRectMake(21, 64 * 10 / 3 + 67 - 64 + 64, sizexla.width, sizexla.height);
    [self.view addSubview:xla];
    
    querenpwd = [[UITextField alloc] initWithFrame:CGRectMake(xla.right, xla.y, 160, xla.height)];
    querenpwd.placeholder = @"请再次输入新密码";
    
    querenpwd.secureTextEntry = YES;
    
    [self.view addSubview:querenpwd];
    
    //的按钮
    _btn = [[UIButton alloc] initWithFrame:CGRectMake(21, 2 * 64 + authLab.bottom, self.view.bounds.size.width - 42, 50)];
    
    _btn.clipsToBounds = YES;
    
    _btn.layer.cornerRadius = 10;
    
    [_btn setTitle:@"确认修改" forState:UIControlStateNormal];
    
    [_btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    _btn.backgroundColor = [UIColor redColor];
    
    [_btn addTarget:self action:@selector(xiugai) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:_btn];
    
}

- (void)click {
    
    [yanzhengBtn setBackgroundColor:[UIColor lightGrayColor]];
    
    [yanzhengBtn setTitle:@"已发送" forState:UIControlStateNormal];
    
    yanzhengBtn.selected = YES;
    
    [BGDateResult getPhoneCodeWithPhoneNim:numFiled.text andType:@"forgetPayPwd" success:^(NSDictionary *dic) {
        
        if ([dic[@"status"] isEqual:@"1"]) {
            
            
            
        }else {
            
            [self showMessage:dic[@"msg"]];
            
        }
        
        
    } failure:^(NSError *error) {
        
    }];
    
}
- (void)showMessage:(NSString *)message {
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
    
    [alertController addAction:okAction];
    
    [self presentViewController:alertController animated:YES completion:nil];
    
}

- (void)xiugai {
    
    [BGDateResult forgetPayPwdWithPhone:numFiled.text andPwd:xpwdFiled.text andAgapwd:querenpwd.text andType:@"forgetPayPwd" andPhoneCode:yzmFiled.text success:^(NSString *status, NSString *msg, NSString *autoRes) {
        
        if ([status isEqualToString:@"1"]) {
            [self showMessage:msg];
        }else {
            [self showMessage:msg];
        }
        
    } failure:^(NSError *error) {
        
    }];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
